package com.ywd.materials.admin.controller;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.util.DateUtils;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ywd.materials.admin.exception.CommonException;
import com.ywd.materials.admin.exception.R;
import com.ywd.materials.admin.properties.StorageConfig;
import com.ywd.materials.admin.service.OssFileService;
import com.ywd.materials.admin.service.impl.FileServiceImpl;
import com.ywd.materials.admin.vo.FileUploadVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author lk
 * @date 2024/6/3 9:50
 */
@AllArgsConstructor
@RestController
@RequestMapping("/file")
@Tag(name = "文件管理")
public class FileController {

    private final OssFileService ossFileService;
    private final FileServiceImpl fileService;

    @GetMapping("/getOssFileToken")
    @Operation(summary = "获取OSS上传令牌")
    @ApiOperationSupport(order = 2)
    public R getOssFileToken() {
        return ossFileService.getOssFileToken();
    }

    @PostMapping("/ossUploadFile")
    @Operation(summary = "上传文件(OSS上传)")
    @ApiOperationSupport(order = 3)
    public R ossUploadFile(@Schema(description = "文件") @RequestPart("file") MultipartFile file) {
        return R.ok(ossFileService.ossUploadFile(file));
    }

    @PostMapping("/ossUploadFileList")
    @Operation(summary = "批量上传文件(OSS上传)")
    @ApiOperationSupport(order = 4)
    public R ossUploadFileList(@Schema(description = "文件") @RequestPart("files") MultipartFile[] file) {
        return R.ok(ossFileService.ossUploadFileList(file));
    }

    @PostMapping("/uploadFile")
    @Operation(summary = "上传文件(服务器上传)")
    public R<FileUploadVo> uploadFile(@RequestPart("file") MultipartFile file) {
        return R.ok(fileService.uploadFile(file));
    }

}
